﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Order.MicroService.Domain;
using Order.MicroService.IRepository;
using Order.MicroService.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Order.MicroService.Repository
{
    public class OrderRepository : BaseRepository<Orders>, IOrderRepository
    {      
        public OrderRepository(MyDbContext myDbContext) : base(myDbContext)
        {
            
        }

        public Orders GetOrders()
        {
            var orders = db.Orders.FromSqlRaw("select * from Orders");
            var rows = db.Database.ExecuteSqlRaw("select * from Orders");
            //return _baseRepository.GetEntity("shabi");
            return db.Orders.Where(x=>x.Id==5).FirstOrDefault();
        }
        public string GetEntity()
        {
            Orders result = base.GetEntity(x => x.Id >= 5);
            Console.WriteLine(db.Entry<Orders>(result).State);
            db.Entry<Orders>(result).State = EntityState.Modified;
            result.OrderName = "ceshi";
            Console.WriteLine(db.Entry<Orders>(result).State);
            return result.OrderName;
        }

        public IEnumerable<Orders> GetOrdersInfo()
        {
            var result = base.GetList(x => x.Id > 0);
             return result;
        }

        public int AddOrders(Orders orders)
        {
            return base.AddEntity(orders);
        }

        //public int updateOrders(int Id)
        //{
        //    Orders result = base.GetEntity(x => x.Id == Id);
        //    if (result != null)
        //    {
        //        result.OrderName = "ceshi";
        //        return base.UpdateEntity(result);
        //    }
        //    else
        //    {
        //        return 0;
        //    }
        //}
    }
}
